package com.yugu.park.system.controller;

import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.yugu.park.system.entity.SysRoleEntity;
import com.yugu.park.system.service.SysRoleService;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.github.pagehelper.PageInfo;

/**
 * 角色信息表
 *
 * @author guxf
 * @email sjzyug@163.com
 * @date 2023-08-17 15:04:07
 */
@Api(tags = {"角色信息表"})
@RestController
@RequestMapping("system/sysrole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 列表
     */

    @ApiOperation(value="分页查询", notes="分页查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResponseUtil.Result<PageInfo<SysRoleEntity>> page (@RequestBody SearchPage<SysRoleEntity> search){
        PageInfo<SysRoleEntity> page = sysRoleService.page(search);
        return ResponseUtil.addSuccess(page);
    }
	@ApiOperation(value="查看详情", notes="查看详情")
    @GetMapping("/{roleId}")
    public ResponseUtil.Result<SysRoleEntity> info(@PathVariable("roleId") String roleId){
		SysRoleEntity sysRole = sysRoleService.getById(roleId);
        return ResponseUtil.addSuccess(sysRole);
    }
    @ApiOperation(value="新增", notes="新增")
    @RequestMapping(value="/save", method= RequestMethod.POST)
    public ResponseUtil.Result<Boolean> save(@RequestBody SysRoleEntity sysRole){
		sysRoleService.save(sysRole);
         return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="新增或修改", notes="新增或修改")
    @RequestMapping(value="/addOrUpdate", method= RequestMethod.POST)
    public ResponseUtil.Result<Boolean> addOrUpdate(@RequestBody SysRoleEntity sysRole){
		sysRoleService.addOrUpdate(sysRole);
         return ResponseUtil.addSuccess(true);
    }
    /**
     * 修改
     */
    @ApiOperation(value="修改", notes="修改")
    @RequestMapping(value="/update", method = RequestMethod.PUT)
    public ResponseUtil.Result<Boolean> update(@RequestBody SysRoleEntity sysRole){
		sysRoleService.updateById(sysRole);
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="删除", notes="删除")
    @RequestMapping(value="/delete", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@RequestBody String[] roleIds){
		sysRoleService.removeByIds(Arrays.asList(roleIds));
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="删除", notes="删除")
    @RequestMapping(value="/{id}", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("id") String id){
    	sysRoleService.removeByIds(Arrays.asList(id.split(",")));
        return ResponseUtil.addSuccess(true);
    }

}
